<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Services\Statistics\SearchCount;
use App\Models\Apple;
use App\Models\Statistic;
use Carbon\Carbon;

class RunAppleProduce extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'cc:run-apple-produce';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {

        $insert =[];

        $ownProductApple = Apple::query()
            ->where('remark','own_tree_produce_apples')
            ->whereDate('created_at',Carbon::today())
            ->sum('money');
        $oneLevelTeamAppleProduceA = Apple::query()
            ->where('remark','1_tree_produce_apples')
            ->whereDate('created_at',Carbon::today())
            ->sum('money');
        $twoLevelTeamAppleProduceA = Apple::query()
            ->where('remark','2_tree_produce_apples')
            ->whereDate('created_at',Carbon::today())
            ->sum('money');
        $appleTreeProduceA = Apple::query()
            ->where('remark','garden_produce_apples')
            ->whereDate('created_at',Carbon::today())
            ->sum('money');

        $insert = [
            ['title'=>'own_tree_produce_apples_'.date("Ymd"),'value'=>$ownProductApple],
            ['title'=>'1_tree_produce_apples_'.date("Ymd"),'value'=>$oneLevelTeamAppleProduceA],
            ['title'=>'2_tree_produce_apples_'.date("Ymd"),'value'=>$twoLevelTeamAppleProduceA],
            ['title'=>'garden_produce_apples_'.date("Ymd"),'value'=>$appleTreeProduceA],

        ];

        Statistic::insert($insert);
    }
}
